import 'package:flutter/material.dart';
import 'package:get_it/get_it.dart';
import 'package:hxdj/common/my_common.dart';
import 'package:hxdj/message/rongcloud/chat/rc_chat_global_viewmodel.dart';

final serviceLocator = GetIt.instance;
bool boolIsInitailized = false;

void setupServiceLocator() {
  if (!boolIsInitailized) {
    // setting
    serviceLocator.registerSingleton<MySettingModel>(MySettingModel());
    serviceLocator.registerSingleton<RCChatGlobalModel>(RCChatGlobalModel());

    boolIsInitailized = true;
  }
}

class MySettingModel extends ChangeNotifier {
  final String keyTitle = "chat_uikit_keyboard";

  double? _keyboardHeight;
  double get keyboardHeight => _keyboardHeight ?? 0;
  set keyboardHeight(double value) {
    if (value > 40 && _keyboardHeight != value) {
      _keyboardHeight = value;
      updateLocalSetting("${keyTitle}keyboardHeight", value.toString());
    }
  }

  updateLocalSetting(String key, String value) async {
    CommonPlugin.sharedPreferences!.setString(key, value);
  }

  init() async {
    String keyboardHeight = CommonPlugin.sharedPreferences!.getString("${keyTitle}keyboardHeight") ?? "0";

    _keyboardHeight = double.parse(keyboardHeight);
  }
}
